package com.example.tests;

import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.*;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;

import com.example.utils.SortedListOf;
import static com.example.tests.ContactDataGenerator.loadContactsFromXmlFile;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import static com.example.fw.ContactHelper.CREATION;

public class ContactCreationTests extends TestBase {
	
	@DataProvider
	public Iterator<Object[]> contactsFromFile() throws IOException {
		return wrapContactsForDataProvider(loadContactsFromXmlFile(new File("contact.xml"))).iterator();
	}

	//@Test(dataProvider = "ramdomValidContactsGenerator")
	@Test(dataProvider = "contactsFromFile")
	public void contactCreationTests(ContactDate contact) throws Exception {

		// save old state
		SortedListOf<ContactDate> oldList = app.getContactHelper()
				.getContacts();

		// actions
		app.getContactHelper().createContact(contact, CREATION);

		// save new state
		SortedListOf<ContactDate> newList = app.getContactHelper()
				.getContacts();

		// compare states
		assertThat(newList, equalTo(oldList.withAdded(contact)));

	}

}
